package labyrinth;


/**
 * A map of the surroundings of an agent
 * 
 * @author Johannes Kulick
 * @version 0.1
 * @licence GNU Lesser Genaral Public Licence
 */
public class Map {

	private int[][] mMatrix;

	public Map(Labyrinth labyrinth) {
		mMatrix = new int[labyrinth.getMatrix().length][labyrinth.getMatrix()[0].length];
		for (int x = 0; x < mMatrix.length; x++) {
			for (int y = 0; y < mMatrix[x].length; y++) {
				mMatrix[x][y] = Labyrinth.UNKNOWN;
			}
		}
	}
	public Map(int[][] matrix) {
		mMatrix = matrix;
	}

	/**
	 * Sets a field state. For internal use.
	 * 
	 * @param pos
	 *            The position
	 * @param value
	 *            The state-value
	 */
	public void set(Position pos, int value) {
		mMatrix[pos.x][pos.y] = value;
	}

	/**
	 * Returns a field state
	 * 
	 * @param pos
	 *            The position of the field
	 * @return An int-value representing the state of this field (see Labyrinth
	 *         class)
	 */
	public int get(Position pos) {
		return mMatrix[pos.x][pos.y];
	}

	/**
	 * Returns the size of a given labyrinth
	 * 
	 * @return The position of the lowest-most-right field.
	 */
	public Position getSize() {
		return new Position(mMatrix.length - 1, mMatrix[0].length - 1);
	}

	public String toString() {
		String result = "";
		for (int i = 0; i < mMatrix.length; i++) {
			for (int j = 0; j < mMatrix[i].length; j++) {
				result += " " + mMatrix[i][j];
			}
			result += "\n";
		}
		return result;
	}

	
}
